import httpClient from "./http-client";
import type { SysOnlineUser } from "@/entity/SysOnlineUser";
import type { ResponseResult } from "@/entity/ResponseResult";
import type { AxiosResponse } from "axios";

export class SysOnlineUserService {
    baseUrl = "/api/v1.0/admin/online";

    async list(searchObj?: SysOnlineUser): Promise<SysOnlineUser[]> {
        return httpClient.post(`${this.baseUrl}/list`, {
            ...searchObj,
        }).then((res: AxiosResponse<ResponseResult<SysOnlineUser[]>>) => {
            if (res.data.data) {
                return Promise.resolve(res.data.data);
            } else {
                throw "no data";
            }
        });
    }

    async forceLogouut(token: string) {
        return httpClient.post(`${this.baseUrl}/force-logout/${token}`, token)
            .then((res: AxiosResponse<ResponseResult<null>>) => {
                return Promise.resolve(res.data.data);
            });
    }
}

const onlineUserService = new SysOnlineUserService();

export default onlineUserService;